﻿namespace ObjectDemo
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Guy guy1 = new Guy() { Cash = 50, Name = "Joe" };
            Guy guy2 = new Guy() { Cash = 100, Name = "Bob" };

            while (true)
            {
                guy1.WriteMyInfo();//
                guy2.WriteMyInfo();//

                Console.WriteLine("Enter an amount: ");
                string howMuch = Console.ReadLine();
                if (howMuch == "") return;
                if (int.TryParse(howMuch, out int result))//
                {
                    Console.WriteLine("Who should give the cash:");

                    string whichGuy = Console.ReadLine();
                    if (whichGuy == "Joe")
                    {
                        int cashGiven = guy1.GiveCash(result);
                        guy2.ReceiveCash(cashGiven);
                    }
                    else if (whichGuy == "Bob")
                    {
                        int cashGiven = guy2.GiveCash(result);
                        guy1.ReceiveCash(cashGiven);
                    }
                    else
                    {
                        Console.WriteLine("Please enter 'Joe' or 'Bob'");
                    }
                }
                else
                {
                    Console.WriteLine("Please enter an amount (or a blank line to exit).");
                }
            }

            Console.ReadKey();
        }
    }

    class Guy
    {
        public int Cash;
        public string Name;

        public void WriteMyInfo()
        {
            Console.WriteLine(Name + " has " + Cash + " bucks.");
        }

        public int GiveCash(int amount)
        {
            if (amount <= 0)
            {
                Console.WriteLine($"{Name} says: {amount} isn't a valid amount");
                return 0;
            }
            if (amount > Cash)
            {
                Console.WriteLine($"{Name} says: I don't have enough cash to give you {amount}");
                return 0;
            }
            Cash -= amount;
            return amount;
        }

        public void ReceiveCash(int amount)
        {
            if (amount < 0)
            {
                Console.WriteLine($"{Name} says: {amount} isn't an amount I'll take");
            }
            else
            {
                Cash += amount;
            }
        }

    }
}
